package stringTest;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.StringTokenizer;
import java.util.regex.Pattern;

import junit.framework.TestCase;

/*------------------------------------------------------------------------------
 * PROJ : TestCase
 * NAME : FileNameTest
 * DESC : 
 * Author : Hosung.Seo
 * VER  : v1.0  * 
 * Copyright 2008 LG CNS All rights reserved
 *------------------------------------------------------------------------------
 *                  Change History                      
 *------------------------------------------------------------------------------
 *    DATE     AUTHOR                      DESCRIPTION                        
 * ----------  ------  --------------------------------------------------------- 
 * 2008. 7. 11.  Hosung  First released.                
 *----------------------------------------------------------------------------
 */

/**
 * <PRE>
 * 
 * </PRE>
 *
 * @author    Hosung.Seo
 * @version   2008. 7. 11.
 * @see       FileNameTest
 */
public class FileNameTest extends TestCase {
	public static final String XSS_REGEXP_PATTERN = "(?i)<[\\s]*a[\\s]*href[^>]*javascript[\\s]*:[^(^)^>]*[(][^)]*[)][^>]*>[^<]*(<[\\s]*/[\\s]*a[^>]*>)*";
    public static final Pattern XSS_PATTERN = Pattern.compile(XSS_REGEXP_PATTERN);
	
    public void testeee() {
        String text = "<a href=JAVASCRIPT:\\alert();>";
        //CharSequence sequence = text.subSequence(0, text.length());
        //Matcher matcher = XSS_PATTERN.matcher(sequence);
        
        System.out.println("--->"+ text.replaceAll("(javascript|JAVASCRIPT)(.)*:(.)*\\)",""));
        System.out.println("00000000000");
    }
    
    
	public void test() {
		String str = "abc.d.ccc.exe";
		String fileExtentionName = "<a href=javascript://www.naver.com>";
	    
		System.out.println(fileExtentionName);
		StringTokenizer tokens = new StringTokenizer( str, "." );
		while ( tokens.hasMoreTokens() ) {
			fileExtentionName = tokens.nextToken();
		}
		int pos = str.lastIndexOf( "." );
		String ext = str.substring( pos + 1  );
		String nm = str.substring(0,pos);
		assertEquals( "abc.d.ccc", nm );
		assertEquals( "exe", ext );
	}

	public void test2() {
		String str = "Java Technology : http://java.sun.com/javame JSRs : http://jcp.org/en/jsr/";
		String fileExtentionName = "";
		String allString = "";
		
		StringTokenizer tokens = new StringTokenizer( str, " " );
		while ( tokens.hasMoreTokens() ) {
			String strTemp = tokens.nextToken();
			System.out.println(strTemp);
			if(strTemp.startsWith( "http://" )) {
				strTemp = "<a href=\'" + strTemp + "\'>" + strTemp + "</a>";
			
			}
			allString += strTemp;
			System.out.println(allString);
			//fileExtentionName = tokens.nextToken();
		}
//		int pos = str.lastIndexOf( "." );
//		String ext = str.substring( pos + 1  );
//		String nm = str.substring(0,pos);
//		assertEquals( "abc.d.ccc", nm );
//		assertEquals( "exe", ext );
	}

	public void test3() {
		Calendar oCalendar = Calendar.getInstance( );  // ?�재 ?�짜/?�간 ?�의 각종 ?�보 ?�기
	
	    System.out.println("?�재 ?? " +  oCalendar.get(Calendar.YEAR));
	    System.out.println("?�재 ?? " + (oCalendar.get(Calendar.MONTH) + 1));
	    System.out.println("?�재 ?? " +  oCalendar.get(Calendar.DAY_OF_MONTH));
	    System.out.println(); // ?�음줄로 ?�갈???�기
	
	    System.out.println("?�재 ?? " +  oCalendar.get(Calendar.HOUR_OF_DAY)); // 24?�간??
	    System.out.println("?�재 �? " +  oCalendar.get(Calendar.MINUTE));
	    System.out.println("?�재 �? " +  oCalendar.get(Calendar.SECOND));
	    System.out.println();
	
	    // 12?�간?�로 ?�재 ??
	    System.out.print("?�재 ?? " +  oCalendar.get(Calendar.HOUR));
	    if (oCalendar.get(Calendar.AM_PM) == 0) System.out.println("am");
	    else System.out.println("pm");
	
	    System.out.println("?�재 초의 1000분의1�? " +  oCalendar.get(Calendar.MILLISECOND));
	
	    System.out.println("?�재 ?�일: " +  oCalendar.get(Calendar.DAY_OF_WEEK)); // ?�요??= 1
	    System.out.println("?�해 �?번째 ?? " + oCalendar.get(Calendar.DAY_OF_YEAR)); // 1??1??= 1
	    System.out.println("?�해 �?번째 �? " + oCalendar.get(Calendar.WEEK_OF_YEAR)); // 1??1?��? = 1
	    String format = "yyyyMMddHHmmssSSS"; 
	    SimpleDateFormat dateFormat = new SimpleDateFormat(format);
	    System.out.println(dateFormat.format(new Date()));

	}
	
	public void test5(){  // 문자???�르�?
		String szText;
		String szKey;
		int nLength = 0;
		int nPrev = 0;
		boolean isNotag = false; 
		boolean isAdddot = false;
		
	    String r_val = "how to get this file for LG Mobile";
	    szKey = " ";
	    int oF = 0, oL = 0, rF = 0, rL = 0; 
	    int nLengthPrev = 0;
	    Pattern p = Pattern.compile("<(/?)([^<>]*)?>", Pattern.CASE_INSENSITIVE);  // ?�그?�거 ?�턴
	   
	    if(isNotag) {r_val = p.matcher(r_val).replaceAll("");}  // ?�그 ?�거
	    r_val = r_val.replaceAll("&amp;", "&");
	    r_val = r_val.replaceAll("(!/|\r|\n|&nbsp;)", "");  // 공백?�거
	 
	    try {
	      byte[] bytes = r_val.getBytes("UTF-8");     // 바이?�로 보�? 
	      if(szKey != null && !szKey.equals("")) {
	        nLengthPrev = (r_val.indexOf(szKey) == -1)? 0: r_val.indexOf(szKey);  // ?�단 ?�치찾고
	        nLengthPrev = r_val.substring(0, nLengthPrev).getBytes("MS949").length;  // ?�치까�?길이�?byte�??�시 구한??
	        nLengthPrev = (nLengthPrev-nPrev >= 0)? nLengthPrev-nPrev:0;    // �??��?분�???�?��?�도록한??
	      }
	    
	      // x�?�� y길이만큼 ?�라?�다. ?��??�깨�?��.
	      int j = 0;

	      if(nLengthPrev > 0) while(j < bytes.length) {
	        if((bytes[j] & 0x80) != 0) {
	          oF+=2; rF+=3; if(oF+2 > nLengthPrev) {break;} j+=3;
	        } else {if(oF+1 > nLengthPrev) {break;} ++oF; ++rF; ++j;}
	      }
	      
	      j = rF;

	      while(j < bytes.length) {
	        if((bytes[j] & 0x80) != 0) {
	          if(oL+2 > nLength) {break;} oL+=2; rL+=3; j+=3;
	        } else {if(oL+1 > nLength) {break;} ++oL; ++rL; ++j;}
	      }

	      r_val = new String(bytes, rF, rL, "UTF-8");  // charset ?�션
	      System.out.println("..." + r_val);
	      if(isAdddot && rF+rL+3 <= bytes.length) {r_val+="...";}  // ...??붙일�?���??�션
	      
	    } catch(UnsupportedEncodingException e){ e.printStackTrace(); }   
	   
	  
	  }
	/**
	 * @param name
	 */
	public FileNameTest( String name ) {
		super( name );
	}

	/** 
	 * 
	 * @throws java.lang.Exception
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
	}

	/** 
	 * 
	 * @throws java.lang.Exception
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

}
